package cn.day13;

import org.junit.Test;

import java.io.*;
import java.util.Scanner;

public class Box {
    @Test
    public void TestReader(){
        BufferedReader br=null;

        try {
            br=new BufferedReader(new FileReader("D:\\ready\\1.txt"));
            int b;
            while ((b=br.read())!=-1){
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    @Test
    public void TestWriter(){
        BufferedWriter bw=null;
        try {
            bw=new BufferedWriter(new FileWriter("D:\\ready\\1.txt",true));
            bw.write(101);
            bw.write(101);
            bw.write(101);
            bw.write(101);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    @Test
    public void TestCopeStream(){
        System.out.println("请输入源地址");
        String f=new Scanner(System.in).nextLine();
        System.out.println("请输入新地址");
        String t=new Scanner(System.in).nextLine();
        InputStream bi=null;
        OutputStream bo=null;
        try {
            bi=new BufferedInputStream(new FileInputStream(f));
            bo=new BufferedOutputStream(new FileOutputStream(t));
            int b;
            while ((b=bi.read())!=-1){
                bo.write(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                bo.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                bi.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    @Test
    public void TestOutputStream(){

    }
}
